package com.xgl.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgl.mapper.PunishmentinfoMapper;
import com.xgl.pojo.Punishmentinfo;
import com.xgl.pojo.RespBean;
import com.xgl.pojo.RespPageBean;
import com.xgl.pojo.Rewardinfo;
import com.xgl.service.IPunishmentinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 学生处罚信息 服务实现类
 * </p>
 *
 * @author 最最帅气的熊国林
 * @since 2021-05-09
 */
@Service
public class PunishmentinfoServiceImpl extends ServiceImpl<PunishmentinfoMapper, Punishmentinfo> implements IPunishmentinfoService {

    @Autowired
    private PunishmentinfoMapper punishmentinfoMapper;

    @Override
    public RespPageBean getPunishmentinfoByPage(Integer currentPage, Integer size, Punishmentinfo punishmentinfo, LocalDate[] beginDateScope) {
        //开启分页
        Page<Punishmentinfo> page = new Page<>(currentPage, size);
        IPage<Punishmentinfo> punishmentinfoIPage = punishmentinfoMapper.getPunishmentinfoByPage(page, punishmentinfo, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(punishmentinfoIPage.getTotal(), punishmentinfoIPage.getRecords());
        return respPageBean;
    }

    @Override
    public RespBean addPunishmentinfo(Punishmentinfo punishmentinfo) {
        if (punishmentinfoMapper.insert(punishmentinfo) == 1){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @Override
    public List<Punishmentinfo> getPunishmentinfo(Integer id) {
        return punishmentinfoMapper.getPunishmentinfo(id);
    }

    @Override
    public RespBean insertHashCode(Integer id, String hashCode) {
        if (punishmentinfoMapper.insertHashCode(id,hashCode) && punishmentinfoMapper.insertPreviousHash(id,hashCode)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
}
